import { Component, OnInit } from '@angular/core';
import { HeroService } from '../../../services/hero.service';
import { NzMessageService,NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-roles',
  templateUrl: './roles.component.html',
  styleUrls: ['./roles.component.css']
})
export class RolesComponent implements OnInit {

  loading = true;
  btn_loading=false;
  public name:string='';
  public profile:string='';
  public roleslist:Array<any>=[];
  public PageIndex:number=1;
  public PageSize:number=10;
  public PageTotal:number;
  constructor(private heroService: HeroService,
              private message: NzMessageService,
              private modalService: NzModalService) { }

  ngOnInit() {
    this.getRoleslist();
  }
  //获取列表数据
  getRoleslist(){
    this.btn_loading=true;
    let url=host+"/main/roles/list";
    let model="nameLike="+this.name+"&profileLike="+this.profile+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.post(url,model).then(result=>{
      this.btn_loading=false;
      if(result.code==0){
        this.roleslist=result.data.pageBean.result;
        this.PageIndex=result.data.pageBean.curPage;  
        this.PageTotal=result.data.pageBean.totalRow;
        this.loading=false;
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }
  delete(value){
    console.log(value);
    let url=host+"/main/roles/del";
    let model='id='+value;
    this.heroService.post(url,model).then(result=>{
        console.log(result.code);
        if(result.code==0){
          this.message.success('删除成功！');
          this.getRoleslist();
        }else{
          this.message.success(result.msg);
        }
    })
  }

  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getRoleslist();
  }
}
